{extend name="base/common"}

{block name="style"}
<link rel="stylesheet" href="__ADMIN__/css/chosen/chosen.css">
<style>
    .shadow{width: 100%;height: 100%;position: absolute;left: 0;top: 0;background: rgba(0,0,0,0.4);z-index: 88;}
    .b{cursor: pointer;}
    .table-responsive{
        overflow-x: visible;
    }
    .col-lg-11 {
        width: 90%;
    }
</style>
{/block}

{block name="page-header"}
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>学员分配</h2>
        <ol class="breadcrumb">
            <li>
                <a href="{:Url('Student/student')}">分校</a>
            </li>
            <li class="active">
                <strong>学员列表</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">
    </div>
</div>
{/block}

{block name="main"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <form method="get" action="">
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input type="text" placeholder="VIP账号或@名字" class="input-sm form-control" name="vip" value="{notempty name='Think.get.vip'}{$Think.get.vip}{/notempty}">
                            <span class="input-group-btn">
                                <button type="submit" class="btn btn-sm btn-primary">查询</button>
                            </span>
                            </div>
                        </div></form>
                    <div class="ibox-tools">
                        <div style="float: left;width: 50%;">
                            <div class="i-checks" style="width: 100px;float: left">
                                <input type="checkbox" value="1" name="all"> 考研
                            </div>
                            <div class="i-checks" style="width: 100px;float: left">
                                <input type="checkbox" value="2" name="all"> 专升本
                            </div>
                            <div class="i-checks" style="width: 100px;float: left">
                                <input type="checkbox" value="3" name="all"> 四六级
                            </div>
                            <div class="i-checks" style="width: 100px;float: left">
                                <input type="checkbox" value="4" name="all"> 雅思
                            </div>
                            <div class="i-checks" style="width: 100px;float: left">
                                <input type="checkbox" value="5" name="all" > 托福
                            </div>
                            &emsp;
                            <button type="submit" onclick='All()' class="btn btn-sm btn-primary">批量操作</button>
                        </div>
                        <a href="javascript:window.history.go(-1);" class="btn btn-white btn-sm"><i class="fa fa-reply"></i> 返回</a>
                    </div>
                </div>
                <div class="ibox-content" style="margin-bottom: 100px">
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th><input class="i-checks check-all" type="checkbox"></th>
                                <th width="10%">姓名</th>
                                <th width="20%">VIP账号</th>
                                <th width="70%">单词分配</th>
                                <!--<th width="50%">课表班型分配</th>-->
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo" key="k"}
                            <tr>
                                <td data-id="{$vo.openid}"><input type="checkbox" class="i-checks  aa" name="input[]"></td>
                                <td width="10%" style="vertical-align: middle">{$vo.name}</td>
                                <td width="20%" style="vertical-align: middle">{$vo.order_id}</td>
                                <td width="70%" style="vertical-align: middle">
                                    <label class="i-checks" style="width: 10%">
                                        <input type="checkbox" value="1" name="words{$k}"
                                        {volist name="$vo.words"  id="vv" } {eq name="$vv" value="1"} checked {/eq} {/volist}> 考研
                                    </label>
                                    <label class="i-checks" style="width: 15%">
                                        <input type="checkbox" value="2" name="words{$k}" {volist name="$vo.words"  id="vv" } {eq name="$vv" value="2"} checked {/eq} {/volist} > 专升本
                                    </label>
                                    <label class="i-checks" style="width: 15%">
                                        <input type="checkbox" value="3" name="words{$k}" {volist name="$vo.words"  id="vv" } {eq name="$vv" value="3"} checked {/eq} {/volist} > 四六级
                                    </label>
                                    <label class="i-checks" style="width: 10%">
                                        <input type="checkbox" value="4" name="words{$k}" {volist name="$vo.words"  id="vv" } {eq name="$vv" value="4"} checked {/eq} {/volist} > 雅思
                                    </label>
                                    <label class="i-checks" style="width: 10%">
                                        <input type="checkbox" value="5" name="words{$k}" {volist name="$vo.words"  id="vv" } {eq name="$vv" value="5"} checked {/eq} {/volist} > 托福
                                    </label>&emsp;|&emsp;
                                    <label style="width: 10%">
                                        <input type="checkbox" id="checkAll{$k}" onclick='checkAll("{$k}")' style="width: 1.3vw;height: 1.3vw;vertical-align: middle" > 全选
                                    </label>
                                    <button type="submit" onclick='changeType("{$k}","{$vo.openid}")' class="btn btn-sm btn-primary">确认</button>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="10">
                                    <div class="page">{$list->render()}</div>
                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<iframe id="iframe" src="" style="height: 80%;width: 392px;z-index: 99;position: absolute;top: 10%;border: 0;left: 32%;background: #fff;display: none;" scrolling="auto" seamless></iframe>
<div class="shadow" style="display: none"></div>
<!-- 模态框（Modal） -->
{/block}

{block name="script"}
<script src="__ADMIN__/js/plugins/iCheck/icheck.min.js"></script>
<script src="__ADMIN__/js/chosen.jquery.js"></script>
<script>
    highlight_subnav("{:Url('Student/index')}");
    $(document).ready(function(){
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
        $('.check-all').on('ifChecked', function(event){
            $('.aa').iCheck('check');
        });

        $('.check-all').on('ifUnchecked', function(event){
            $('.aa').iCheck('uncheck');
        });
    });
    function changeType(i,id){
        var name = 'words'+i;
        var obj = document.getElementsByName(name);
        var check_val = [];
        for(var k in obj){
            if(obj[k].checked)
                check_val.push(obj[k].value);
        }
        if (check_val == ''){
            updateAlert('请选择类型', 'error');
            return false;
        }
        $.ajax({
            type:"post",
            url:"{:Url('Student/play')}",
            data:{id:id,type:check_val},
            success:function(data){
                if(data.code == 1){
                    updateAlert(data.msg ,'success');
                    history.go(0);
                } else {
                    updateAlert(data.msg, 'error');
                }
            }
        });
        return false;
    }
    function checkAll(id){
        //1.获取编号前面的复选框
        var checkAllEle = document.getElementById("checkAll"+id);
        var na = 'words'+id;
        //2.对编号前面复选框的状态进行判断
        if(checkAllEle.checked==true){
            //3.获取下面所有的复选框
            var checkOnes = document.getElementsByName("words"+id);
            //4.对获取的所有复选框进行遍历
            for(var i=0;i<checkOnes.length;i++){
                //5.拿到每一个复选框，并将其状态置为选中
                $("input[name='"+na+"']").iCheck('check');
            }
        }else{
            //6.获取下面所有的复选框
            var checkOnes = document.getElementsByName("words"+id);
            //7.对获取的所有复选框进行遍历
            for(var i=0;i<checkOnes.length;i++){
                //8.拿到每一个复选框，并将其状态置为未选中
                $("input[name='"+na+"']").iCheck('uncheck');
            }
        }
    }
    function All(){
        var Arr = [];
        $("tr td:nth-child(1) .icheckbox_square-green").each(function(){
            if($(this).hasClass("checked")){
                Arr.push($(this).parent().data("id"));
            }
        });
        if(Arr.length===0){
            updateAlert("未选择操作列表",'error');
            return false;
        }
        var ob = document.getElementsByName('all');
        var c_val = [];
        for(var k in ob){
            if(ob[k].checked)
                c_val.push(ob[k].value);
        }
        if (c_val == ''){
            updateAlert('请选择类型', 'error');
            return false;
        }
        $.ajax({
            type:"post",
            url:"{:Url('Student/plays')}",
            data:{all:Arr,type:c_val},
            success:function(data){
                if(data.code == 1){
                    updateAlert(data.msg ,'success');
                    history.go(0);
                } else {
                    updateAlert(data.msg, 'error');
                }
            }
        });
        return false;
    }
</script>
{/block}